﻿using Fast.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Fast.AspNetCore.WebApi.Tests.Services
{

    public interface IUserService
    {
        Task AddUser(User user);
        Task<User> GetUser(int userId);
    }

    [DynamicApiController]
    public class UserService : IUserService
    {
        List<User> Users = new List<User>
        {
            new User{ Id=1,Name="张三"},
            new User{ Id=2,Name="李四"},
            new User{ Id=3,Name="王五"},

        };
        public async Task AddUser(User user)
        {
            await Task.Run(() =>
            {
                Users.Add(user);
            });
        }
        public async Task<User> GetUser(int userId)
        {
            return await Task.Run(() =>
            {
                return Users.FirstOrDefault(p => p.Id == userId);
            });
        }

        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        public string Get(int id)
        {
            return "value";
        }

        public void Post([FromBody] string value)
        {
        }

        public void Put(int id, [FromBody] string value)
        {
        }

        public void Delete(int id)
        {
        }
    }
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}
